<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<HEAD>
    <TITLE>SocketJS: Realtime Javascript Sockets</TITLE>
    <meta name="description" content="Sockets in Javascript">
    <meta name="author" content="Manfred Weber">
    <meta name="keywords" content="realtime,realtimejs,javascript,socket,flash,real,sockets,js,multiuser,dschini">
    <style>
        .title {
            font-face:Verdana,Arial,sans-serif;
            font-size:24px;
            color:white;
        }
        .standard {
            font-face:Verdana,Arial,sans-serif;
            font-size:16px;
            color:white;
        }
    </style>
</HEAD>
<SCRIPT LANGUAGE=JavaScript>
    <!--
    /*
     * This is just a help function !!!
     */
    var nickname;
    function connect_user(){
        /*
         window.document.socket.SetVariable("data", "PASS xxx");
         window.document.socket.TCallLabel("/", "send" );
         window.document.socket.SetVariable("data", "NICK "+nickname);
         window.document.socket.TCallLabel("/", "send" )
         document.getElementById("output").value += "\nNICK "+nickname;
         window.document.socket.SetVariable("data", "USER "+nickname+" 0 * : undefined");
         window.document.socket.TCallLabel("/", "send" )
         document.getElementById("output").value += "\nUSER "+nickname+" 0 * : undefined";
         window.document.socket.SetVariable("data", "JOIN #findthebug");
         window.document.socket.TCallLabel("/", "send" )
         document.getElementById("output").value += "\nJOIN #findthebug";
         */
        window.document.socket.SetVariable("data", "NICK "+nickname);
        window.document.socket.TCallLabel("/", "send" )
        document.getElementById("output").scrollTop = document.getElementById("output").scrollHeight;
    }

    /*
     * ----------------------------------
     * SocketJS Functions
     * ----------------------------------
     * (c) 2006 by Manfred Weber
     * ----------------------------------
     */
    /*
     * SocketOnInit()
     * Event Handler is called when Flash File is loaded
     */
    function SocketOnInit(){};
    /*
     * SocketOnData()
     * Event Handler is called when received Data
     */
    function SocketOnData(data){
        document.getElementById("output").value += "\n"+data;
        document.getElementById("output").scrollTop = document.getElementById("output").scrollHeight;
    }
    /*
     * SocketOnConnect(success);
     * Event Handler is called when socket is connected
     */
    function SocketOnConnect(success){
        if(success=="true"){
            document.getElementById("output").value += "\n Connection established";
            connect_user();
        } else{
            document.getElementById("output").value += "\n Connection failed";
        }
    }
    /*
     * SocketOnClose
     * Event Handler is calles when socket is closed
     */
    function SocketOnClose(){
        document.getElementById("output").value += "\n Connection closed";
    }
    /*
     * SocketClose()
     * Close the Socket
     */
    function SocketClose(){
        window.document.socket.TCallLabel("/", "close" );
    }
    /*
     * SocketConnect(host,port)
     * Connect to socket. Notice that host must be the same where the .swf file resides!
     */
    function SocketConnect(host,port){
        nickname = document.getElementById("nickname").value;
        window.document.socket.SetVariable("host", host);
        window.document.socket.SetVariable("port", port);
        window.document.socket.TCallLabel("/", "connect" );
    }
    /*
     * SocketSend(data)
     * Send data to open socket
     */
    function SocketSend(data){
        window.document.socket.SetVariable("data", data);
        window.document.socket.TCallLabel("/", "send" )
    }
    //-----------------------------------------------
    //-->
</SCRIPT>


<BODY bgcolor="#ffffff">
<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
           codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
           width=1 height=1 id="socket">
    <param name=movie value="socket.swf">
    <param name=quality value=high>
    <embed src="socket.swf" quality=high width=1 height=1 type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" name="socket" swLiveConnect="true">
    </embed>
</object></p>
<form name="form1" action="#">
    <table width="100%"><tr><td align="center">
        <table style="border:1px solid black" cellpadding="15" width="500" bgcolor="#8e5275">
            <tr><td>
                <font face="Verdana,Arial" size="36px" color="white"><b>SocketJS</b></font><br/></td>
            </tr>
            <tr><td>
                <table width="100%" bgcolor="#eeeeee" style="border:1px solid black">
                    <tr>
                        <td width="75%">
                            <input type="text" style="width:100%" name="nickname" id="nickname" value="Enter your Nickname!" onClick="this.value='';">  </td>
                        <td width="25%">
                            <input style="width:100%" type="button" value="Connect" onClick="SocketConnect('localhost',6666);">  </td>
                    </tr><tr>
                    <td height="150" colspan="2">
    <textarea style="width:100%;height:100%;background-color:#ddd" id="output" name="output">Enter Nickname and Connect!
To get a list of commands type:HELPOP USERCMDS</textarea>  </td>
                </tr><tr>
                    <td width="75%">
                        <input type="text" style="width:100%" name="input" id="input" value="HELPOP USERCMDS">  </td>
                    <td width="25%">
                        <input type="button" style="width:100%" name="send" value="Send" onClick="SocketSend(document.getElementById('input').value);">  </td>
                </tr>
                </table>
            </td></tr>
        </table>
    </td></tr></table>
</form>



</BODY>
</HTML>